<div class="form-horizontal">
	<div class="form-group">
		<label class="col-sm-2 control-label">手机号码：</label>
		<div class="col-sm-8">
			<input type="text" id="txtBindPhone" name="phone" value="<{$user_info['mobile']}>"  class="form-control">
		</div>
	</div>
	<div class="form-group">
		<label class="col-sm-2 col-xs-12 control-label">验证码：</label>
		<div class="col-sm-3 col-xs-6">
			<input type="text" class="form-control"  name="txtPhoneCode" id="txtPhoneCode">
		</div>
		<div class="col-sm-2 col-xs-4">
			<button class="btn btn-white" onclick="send_code(this)" >获得验证码</button>
		</div>
			
		 
	</div>
	<div class="form-group">
	<div class="col-sm-2"></div>
	<div class="col-sm-8">
		<button  type="button" class="btn-primary btn"  id="save_phone_btn" onclick="save_phone(this)"  data-loading-text="提交中……">确定</button>
	</div>
</div>
</div>
<script type="text/javascript">

function send_code(obj){
	$(obj).removeAttr("onClick");
	var phone=$("#txtBindPhone").val();
	$.getJSON("/User/send_code",{phone:phone},function(data){
		if(data.error>0){
			$(obj).attr("onClick","send_code(this)");
			dialog(data.msg);
		}else{
			time_wait(obj);
			$("#txtPhoneCode").val(data.msg);
		}
	})
	
}
//绑定手机
function save_phone(obj){
	$(obj).removeAttr("onClick");
	var phone=$("#txtBindPhone").val();
	var txtPhoneCode=$("#txtPhoneCode").val();
	$.getJSON("/User/bingPhone",{phone:phone,txtPhoneCode:txtPhoneCode},function(data){
 
			dialog(data.msg);
		 	$(obj).attr("onClick","save_phone(this)");
	})
}

/*****验证码等待1分钟**/
function time_wait(obj,savebg){
	window.wait=60;
	time(obj);
	function time(obj) {
		if (wait == 0) {        
			$(obj).html('获取验证码');
			if(savebg==1){
				$(obj).css('background','#009FF0');
			}
			wait = 60;
			$(obj).attr("onClick","send_code(this)");
			
		} else { 
			$(obj).attr("onClick","javascript:");
			$(obj).html("重新发送(" + wait + ")");
			$(obj).val("重新发送(" + wait + ")");
			if(savebg==1){
				$(obj).css('background','#ccc');
			}
			wait--;
			setTimeout(function() {
				time(obj)
			},
			1000);
			 
		}
	}   
}
</script>

